<%- include fheader.ejs%>

<!--<header class="ui-header ui-header-stable ui-border-b">-->
        <!--<h1>登录</h1>-->
    <!--</header>-->
<section  class="ui-container">
    <div style="text-align: center;padding: 10px 10px 20px"><img src="/wx/img/logo.jpg" width="80"></div>
    <div class="ui-form ui-border-t">
        <form>
            <div class="ui-form-item ui-form-item-show ui-border-b">
                <label>
                    手机号码
                </label>
                <input id="mobile" type="text" placeholder="请输入手机号码" value=""/>
            </div>
            <div class="ui-form-item ui-form-item-show ui-border-b">
                <label>
                    验证码
                </label>
                <input  id="smscode" type="text" placeholder="请输入验证码" value="" style="width:60%;"/>
                <input type="button" id="btnGetSmsCode" value="发送验证码" class="ui-btn ui-btn-primary" style="background-color:#0baae4;vertical-align: middle;padding: 0;width: 100px; float: right; margin-top: 7px">
            </div>
            <div style="text-align: center;padding: 15px">
                <input type="hidden" id="token" name="_token" value="<%= token%>">
                <button id="btnLogin" type="button" class="ui-btn ui-btn-primary ui-btn-lg">登录</button>
            </div>

        </form>
    </div>
</section>
<script src="//cdn.juqingdata.com/assets/js/hashes.js"></script>

<script>
    $(function(){

        var SEND_VCODE = '/rest/svcLogin/mdGenSMS';
        var CHECK_VCODE = '/rest/svcLogin/mdVerifySMSByInputCode';
        var UPDATE_USER = '/rest/svcLogin/updateWxUserBusi';


       //mobile,smscode,btnBindCard,btnGetSmsCode
        var $btnGetSmsCode = $('#btnGetSmsCode');
        $btnGetSmsCode.on('touchend', function () {
            if ($btnGetSmsCode.hasClass('disabled')) {
                return;
            }
            var phoneNo = $('#mobile').val();

            var regexp = new RegExp("^(13[0-9]|15[012356789]|17[0135678]|18[0-9]|14[57])[0-9]{8}$", 'ig');
            if (!regexp.test(phoneNo)) {
                juq.showTipSuc('手机号码错误');
                return;
            }
            var p = {
                cellno: phoneNo,
                udid: ''
            };
            var ov = $btnGetSmsCode.val();
            $btnGetSmsCode.addClass('disabled');
            juq.fpost(SEND_VCODE, p, function () {
                var wt = 60;
                var si = setInterval(function () {
                    if (--wt < 1) {
                        si && clearInterval(si);
                        $btnGetSmsCode.removeClass('disabled').val(ov);
                    } else {
                        $btnGetSmsCode.val('重新发送' + '(' + wt + ')')
                    }
                }, 1000);
                juq.showTipSuc('验证码发送成功');
            }, function (res, info) {
                $btnGetSmsCode.removeClass('disabled').text(ov);
                juq.showTipErr(info);
            });
        });


        var CARD_LIST_URL = '<%= retUrl%>'||'/rest/svcWxPage/custCardList';

        $('#btnLogin').tap(function(){

            var time = (+new Date());
            var mobile = $('#mobile').val();
            var randCode = $('#smscode').val();

            if(!check()){
                return;
            }
            var vp = {
                cellno: mobile,
                rand_code: randCode,
                udid: ''
            };
            var p = {
                cellno: mobile,
                rand_code: randCode,
                udid: ''
            };


        juq.showLoading();
        juq.fpost(CHECK_VCODE, vp, function (codeRes) {
            juq.fpost(UPDATE_USER, p, function (uRes) {
                location.href = CARD_LIST_URL;
            }, function (res, info) {
                juq.hideLoading();
                juq.showTipErr(info);
            })
        }, function (res, info) {
            juq.hideLoading();
            juq.showTipErr(info);
        });
        });


        function check(){
            var res = true;
            var mobile = $('#mobile').val();
            var randCode = $('#smscode').val();
            var regexp = new RegExp("^(13[0-9]|15[012356789]|17[0135678]|18[0-9]|14[57])[0-9]{8}$", 'ig');
            if (mobile == '') {
                juq.showTipSuc('手机号不能为空');
                res = false;
            }
            if (randCode == '') {
                juq.showTipSuc('验证码不能为空');
                res = false;
            }
            if (!regexp.test(mobile)) {
                juq.showTipSuc('手机号码错误');
                res = false;
            }
            return res;
        }
    })
</script>
<%- include ftailer.ejs%>